package com.efuture.servlet.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @description: 通过request获取请求头数据
 * @author zhaoshanshan
 * @date 2021/10/2 10:24 下午
 * @version 1.0
 */
@WebServlet("/GetServletHeader")
public class GetServletHeader extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String haedName = headerNames.nextElement();
            String haedValue = request.getHeader(haedName);
            System.out.println(haedName+":"+haedValue);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
